<form method="post">
	<table>
		<tbody>
			<?php foreach($this->data['local'] as $localCol) { ?>
				<?php if(empty($localCol['auto_incr'])) { ?>
					<?php $postField = @$this->data['post']['local'][$localCol['column_name']]; ?>
					<tr>
						<td style="white-space: nowrap;">
							<?php echo $localCol['view_name']; ?>
							<?php if($localCol['notnull']) echo '*'; ?>
						</td>
						<td style="width: 100%;">
							<?php if($localCol['notnull']) { ?>
								<input type="hidden" name="required[<?php echo $localCol['column_name']; ?>]" value="<?php echo $localCol['type']; ?>" />
							<?php } ?>
							<?php if(is_array($localCol['reference'])) { ?>
								<?php echo $this->formSelect("local[{$localCol['column_name']}]", $postField, array('class' => $localCol['type'].' '.(($localCol['notnull']) ? 'required' : '')), $localCol['reference']); ?>
							<?php } elseif($localCol['type'] == 'boolean') { ?>
								<input type="radio" class="<?php if($localCol['notnull']) echo 'required'; ?> <?php echo $localCol['type']; ?>" name="local[<?php echo $localCol['column_name']; ?>]" id="local-<?php echo $localCol['column_name']; ?>-true" value="true" <?php if(!empty($postField) && ($postField == 'true')) echo 'checked="checked"'  ?> />
								<label for="local-<?php echo $localCol['column_name']; ?>-true">Sim</label>
								<br/>
								<input type="radio" class="<?php if($localCol['notnull']) echo 'required'; ?> <?php echo $localCol['type']; ?>" name="local[<?php echo $localCol['column_name']; ?>]" id="local-<?php echo $localCol['column_name']; ?>-false" value="false" <?php if(!empty($postField) && ($postField == 'false')) echo 'checked="checked"'  ?> />
								<label for="local-<?php echo $localCol['column_name']; ?>-false">Não</label>
							<?php } else { ?>
								<input type="text" class="<?php if($localCol['notnull']) echo 'required'; ?> <?php echo $localCol['type']; ?>" name="local[<?php echo $localCol['column_name']; ?>]" value="<?php if(!empty($postField)) echo $postField; ?>" />
							<?php } ?>
							<?php if(isset($this->data['errors']['local'][$localCol['column_name']])) { ?>
								<br />
								<small class="error"><?php echo implode('<br/>', $this->data['errors']['local'][$localCol['column_name']]); ?></small>
							<?php } ?>
						</td>
					</tr>
				<?php } ?>
			<?php } ?>
			<?php if(!empty($this->data['nms'])) { ?>
				<?php $key = 0; ?>
				<?php foreach($this->data['nms'] as $keyNm => $nm) { ?>
					<tr>
						<td style="white-space: nowrap;"><?php echo $nm['info']['view_table']; ?></td>
						<td style="width: 100%;">
							<a href="javascript:void(0);" style="cursor: pointer;" onclick="NmBlock.addNm(this, '<?php echo $nm['info']['schema'].'-'.$nm['info']['table']; ?>')">Adicionar</a>
							<ul class="nm-list">
								<?php if(isset($nm['data'])) { ?>
									<?php foreach($nm['data'] as $data) { ?>
										<li>
											<a href="javascript:void(0);" class="edit-nm-item">Editar</a>
											<span class="delete-nm-item">X</span>
											<table style="width: 600px; background: #FFF; display: none;">
												<thead>
													<tr>
														<td colspan="2">
															<?php foreach($nm['info'] as $kInfo => $fInfo) { ?>
																<input type="hidden" name="nm[<?php echo $key; ?>][info][<?php echo $kInfo; ?>]" value="<?php echo $fInfo; ?>" />
															<?php } ?>
															<h3>Edite as informações do relacionamento</h3>
														</td>
													</tr>
												</thead>
												<tbody>
													<?php foreach($nm['columns'] as $nmCol) { ?>
														<?php if(empty($nmCol['auto_incr'])) { ?>
															<tr>
																<td style="white-space: nowrap;">
																	<?php echo $nmCol['view_name']; ?>
																	<?php if($nmCol['notnull']) echo '*'; ?>
																</td>
																<td style="width: 100%;">
																	<?php if($nmCol['notnull']) { ?>
																		<input type="hidden" name="nm[<?php echo $key; ?>][required][<?php echo $nmCol['column_name']; ?>]" value="<?php echo $nmCol['type']; ?>" />
																	<?php } ?>
																	<?php if(is_array($nmCol['reference'])) { ?>
																		<?php echo $this->formSelect("nm[$key][columns][{$nmCol['column_name']}]", (isset($data[$nmCol['column_name']])) ? $data[$nmCol['column_name']] : null, array('class' => ($nmCol['type'].' '.($nmCol['notnull']) ? 'required' : '')), $nmCol['reference']); ?>
																	<?php } elseif($nmCol['type'] == 'boolean') { ?>
																		<input type="radio" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[<?php echo $key; ?>][columns][<?php echo $nmCol['column_name']; ?>]" id="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>-true" value="true" <?php if(isset($data[$nmCol['column_name']]) && ($data[$nmCol['column_name']] == 'true')) echo 'checked="checked"';?>/>
																		<label for="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>">Sim</label>
																		<br/>
																		<input type="radio" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[<?php echo $key; ?>][columns][<?php echo $nmCol['column_name']; ?>]" id="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>-false" value="false" <?php if(isset($data[$nmCol['column_name']]) && ($data[$nmCol['column_name']] == 'false')) echo 'checked="checked"';?>/>
																		<label for="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>">Não</label>
																	<?php } else { ?>
																		<input type="text" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[<?php echo $key; ?>][columns][<?php echo $nmCol['column_name']; ?>]" value="<?php if(isset($data[$nmCol['column_name']])) echo $data[$nmCol['column_name']]; ?>" />
																	<?php } ?>
																	<?php if(isset($this->data['errors']['nm'][$keyNm][$nmCol['column_name']])) { ?>
																		<br />
																		<small class="error"><?php echo implode('<br/>', $this->data['errors']['nm'][$keyNm][$nmCol['column_name']]); ?></small>
																	<?php } ?>
																</td>
															</tr>
														<?php } ?>
													<?php } ?>
												</tbody>
												<tfoot>
													<tr>
														<td colspan="2">
															<a href="javascript:void(0);" class="nm-save">Salvar</a>
														</td>
													</tr>
												</tfoot>
											</table>
										</li>
										<?php $key++; ?>
									<?php } ?>
								<?php } ?>
							</ul>
						</td>
					</tr>
				<?php } ?>
			<?php } ?>
			<tr>
				<td colspan="2" style="text-align: center;">
					<input type="submit" value="Salvar" />
					<input type="reset" value="Redefinir" />
				</td>
			</tr>
		</tbody>
	</table>
</form>
<div style="display: none;">
	<?php if(!empty($this->data['nms'])) { ?>
		<?php foreach($this->data['nms'] as $nm) { ?>
			<ul id="<?php echo $nm['info']['schema'].'-'.$nm['info']['table']; ?>">
				<li>
					<a href="javascript:void(0);" class="edit-nm-item">Editar</a>
					<span class="delete-nm-item">X</span>
					<table style="width: 600px; background: #FFF;">
						<thead>
							<tr>
								<td colspan="2">
									<?php foreach($nm['info'] as $kInfo => $fInfo) { ?>
										<input type="hidden" name="nm[key][info][<?php echo $kInfo; ?>]" value="<?php echo $fInfo; ?>" />
									<?php } ?>
									<h3>Edite as informações do relacionamento</h3>
								</td>
							</tr>
						</thead>
						<tbody>
							<?php foreach($nm['columns'] as $nmCol) { ?>
								<?php if(empty($nmCol['auto_incr'])) { ?>
									<tr>
										<td style="white-space: nowrap;">
											<?php echo $nmCol['view_name']; ?>
											<?php if($nmCol['notnull']) echo '*'; ?>
										</td>
										<td style="width: 100%;">
											<?php if($nmCol['notnull']) { ?>
												<input type="hidden" name="nm[key][required][<?php echo $nmCol['column_name']; ?>]" value="<?php echo $nmCol['type']; ?>" />
											<?php } ?>
											<?php if(is_array($nmCol['reference'])) { ?>
												<?php echo $this->formSelect("nm[key][columns][{$nmCol['column_name']}]", null, array('class' => ($nmCol['type'].' '.($nmCol['notnull']) ? 'required' : '')), $nmCol['reference']); ?>
											<?php } elseif($nmCol['type'] == 'boolean') { ?>
												<input type="radio" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[key][columns][<?php echo $nmCol['column_name']; ?>]" id="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>-true" value="true" />
												<label for="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>">Sim</label>
												<br/>
												<input type="radio" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[key][columns][<?php echo $nmCol['column_name']; ?>]" id="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>-false" value="false" />
												<label for="nm-<?php echo $nm['info']['table'].'-'.$nmCol['column_name']; ?>">Não</label>
											<?php } else { ?>
												<input type="text" class="<?php if($nmCol['notnull']) echo 'required'; ?> <?php echo $nmCol['type']; ?>" name="nm[key][columns][<?php echo $nmCol['column_name']; ?>]" value="" />
											<?php } ?>
										</td>
									</tr>
								<?php } ?>
							<?php } ?>
						</tbody>
						<tfoot>
							<tr>
								<td colspan="2">
									<a href="javascript:void(0);" class="nm-save">Salvar</a>
								</td>
							</tr>
						</tfoot>
					</table>
				</li>
			</ul>
		<?php } ?>
	<?php } ?>
</div>
<div id="test"></div>